/**
 * Copyright 2015 Software innovation and R & D center. All rights reserved.
 * File Name: bankDao.java
 * Encoding UTF-8
 * Version: 0.0.1
 * History:	2017年1月14日
 */
package transactiondemo.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import TOOL.jdbcTool;

/**
 * 转账dao userin userout
 * @author: qun.xie
 * @version Revision: 0.0.1
 * @Date: 2017年1月14日
 */
public class bankDao {
	/**
	 * 收账
	 * @author: qun.xie
	 * @param conn
	 * @param username
	 * @param money
	 */
 public static  void userin(Connection conn,String username,int money) {
	//Connection conn = null;
	PreparedStatement psmt =null;
	ResultSet rs = null;
	
	try {
		//conn = jdbcTool.getConnection();
		String sql = "update bankp set money = money + ? where username = ?";
		psmt = conn.prepareStatement(sql);
		psmt.setInt(1, money);
		psmt.setString(2, username);
		psmt.executeUpdate();
	} catch (SQLException e) {
		e.printStackTrace();
	}finally{
		jdbcTool.close(null, psmt, rs);
	}
	
	
}
 /**
  * 出账
  * @author: qun.xie
  * @param conn
  * @param username
  * @param money
  */
 public static  void userout(Connection conn,String username,int money) {
	// Connection conn = null;
		PreparedStatement psmt =null;
		ResultSet rs = null;
		
		try {
		//	conn = jdbcTool.getConnection();
			String sql = "update bankp set money = money - ? where username = ?";
			psmt = conn.prepareStatement(sql);
			psmt.setInt(1, money);
			psmt.setString(2, username);
			psmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			jdbcTool.close(null, psmt, rs);
		}
 }
}
